<?php
include "../config/koneksi.php";
//include "../config/library.php";
//include "../config/fungsi_indotgl.php";
//include "../config/fungsi_combobox.php";
include "../config/class_paging.php";

$act=$_GET['act'];
if($act=='hapus'){
	//echo "woi : ";
	mysql_query("DELETE FROM matpel WHERE kd_matpel='$_GET[kd_matpel]'");
	echo "<meta content='0;media.php?module=matpel' http-equiv='refresh' /> ";
}
	
if(isset($_POST['submit']))
{
/*  
*/
	if($act=='input'){
		//echo "kd_matpel : " . $_POST[kd_matpel] . "<br>";
		
		$query = mysql_query("insert into matpel (
		kd_matpel, nama_matpel) values 
		('$_POST[kd_matpel]', 
		'$_POST[nama_matpel]') ");
		echo "<meta content='0;media.php?module=matpel' http-equiv='refresh' /> ";
	}	
	if($act=='edit'){
		//echo "kd_matpel : " . $_POST[kd_matpel] . "<br>";
		
		mysql_query("UPDATE matpel SET nama_matpel       = '$_POST[nama_matpel]'
                             WHERE kd_matpel   = '$_POST[kd_matpel]'");
		
		//echo "kd_matpel : " . $_POST[nama] . "<br>";
		echo "<meta content='0;media.php?module=matpel' http-equiv='refresh' /> ";
	}	
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SMK Pasundan Rancaekek</title>

<link href="../css/templatemo_style.css" rel="stylesheet" type="text/css" />

<link rel="stylesheet" type="text/css" href="../css/ddsmoothmenu.css" />
<script type="text/javascript" src="../scripts/jquery.min.js"></script>
<script type="text/javascript" src="../scripts/ddsmoothmenu.js">

</script>

<script type="text/javascript">

ddsmoothmenu.init({
	mainmenuid: "templatemo_menu", //menu DIV id
	orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
	classname: 'ddsmoothmenu', //class added to menu's outer DIV
	//customtheme: ["#1c5a80", "#18374a"],
	contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})

</script>
</head>

<body id="subpage">

<div id="templatemo_outer_sub_wrapper">
	<div id="templatemo_sub_wrapper">
    
    	<div id="templatemo_header_admin">		
            <?php
			include "menu_admin.php";
			?>
            <div class="cleaner"></div>

        </div> <!-- end of templatemo header -->
        
        <div id="templatemo_main">
        
          	<div class="col_w960 col_w960_last">
				<div class="col_w300 float_r">
                
                    <h3>Tentang Sekolah</h3>
                    <?php 
					include "menu_kiri.php";
					?>
                
                </div>  
                <div class="col_w600 float_l">
                    
                    <h2>Data Mata Pelajaran</h2>
        		<input type=button value='Data Mata Pelajaran' onclick="window.location.href='?module=matpel'">
        		<input type=button value='Tambah Mata Pelajaran' onclick="window.location.href='?module=matpel&act=tambahmatpel'">
				
        		<div id="contact_form">
				<?php
				switch($_GET[act]){
				default:
					echo "
          <form method=get action='$_SERVER[PHP_SELF]'>
          <input type=hidden name=module value=matpel>
          <div id=paging>Masukkan Mata Pelajaran : <input type=text name='nama_matpel'> <input type=submit value=Cari></div>
          </form>";

    if (empty($_GET['nama_matpel'])){
    echo "<table class='ijo'>  
          <tr id='ijo'><th>No</th><th>kd matpel</th><th>Mata Pelajaran</th> <th></th></tr>";

    $p      = new Paging;
    $batas  = 15;
    $posisi = $p->cariPosisi($batas);

    $tampil = mysql_query("SELECT * from matpel ORDER BY kd_matpel ASC LIMIT $posisi,$batas");
    
  
    $no = $posisi+1;
    while($r=mysql_fetch_array($tampil)){      
      echo "<tr><td>$no</td>
                <td>$r[kd_matpel]</td>
                <td>$r[nama_matpel]</td>                
		            <td><a href=?module=matpel&act=editmatpel&kd_matpel=$r[kd_matpel]>Edit</a> | 
		                <a href='$aksi?module=matpel&act=hapus&kd_matpel=$r[kd_matpel]' onClick=\"return confirm('Anda yakin akan menghapus $r[nama_matpel]?')\">Hapus</a></td>
		        </tr>";
      $no++;
    }
    echo "</table>";

    $jmldata = mysql_num_rows(mysql_query("SELECT * FROM matpel"));
      
    $jmlhalaman  = $p->jumlahHalaman($jmldata, $batas);
    $linkHalaman = $p->navHalaman($_GET[halaman], $jmlhalaman);

    echo "<div id=paging>$linkHalaman</div><br>";
 
    break;    
    }
    else{
    echo "<table>  
          <tr><th>No</th><th>Kode matpel</th><th>Mata Pelajaran</th><th>aksi</th></tr>";

    $p      = new Paging9;
    $batas  = 15;
    $posisi = $p->cariPosisi($batas);

    $tampil = mysql_query("SELECT * FROM matpel WHERE matpel LIKE '%$_GET[nama_matpel]%' ORDER BY kd_matpel ASC LIMIT $posisi,$batas");
      
    $no = $posisi+1;
    while($r=mysql_fetch_array($tampil)){
      echo "<tr><td>$no</td>
                <td>$r[kd_matpel]</td>
                <td>$r[nama_matpel]</td>                
		            <td><a href=?module=matpel&act=editmatpel&kd_matpel=$r[kd_matpel]>Edit</a> | 
		                <a href='$aksi?module=matpel&act=hapus&kd_matpel=$r[kd_matpel]'>Hapus</a></td>
		        </tr>";
      $no++;
    }
    echo "</table>";

    $jmldata = mysql_num_rows(mysql_query("SELECT * FROM matpel WHERE matpel LIKE '%$_GET[nama_matpel]%'"));
    
    $jmlhalaman  = $p->jumlahHalaman($jmldata, $batas);
    $linkHalaman = $p->navHalaman($_GET[halaman], $jmlhalaman);

    echo "<div id=paging>$linkHalaman</div><br>";
 
    break;    
    }
					break;
				case "tambahmatpel":
					?>
					<form method="post" name="contact" action="<?php echo $_SERVER['PHP_SELF']; ?>?module=matpel&act=input">
                        
						<table class='putih' border="0" width="650">
						<tr>
						<td colspan="4">
						<ul class="templatemo_list">
						<li><strong>DATA MATA PELAJARAN</strong></li>
						</ul>
						</td>
						</tr>
						<tr>
						<td>Kd Mata Pelajaran</td> <td colspan="3"> <input type="text" name="kd_matpel" size="10" /> </td>                        
						</tr>
						<tr>
						<td>Mata Pelajaran </td> <td colspan="3"> <input type="text" name="nama_matpel" size="30" /> </td>                        
						</tr>						
						
						<tr>
						<td>						
						</td>
						<td colspan="3">				
                        <input type="submit" value="Simpan" id="submit" name="submit" class="submit_btn float_l" />
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="reset" value="Reset" id="reset" name="reset" class="submit_btn float_l" />
						</td>						
						</tr>
						</table>					
                    </form>
					<?php
					break;
					
				case "editmatpel":
				$edit = mysql_query("SELECT * FROM matpel WHERE kd_matpel='$_GET[kd_matpel]' ");
				$r    = mysql_fetch_array($edit);
					?>
					<form method="post" name="contact" action="<?php echo $_SERVER['PHP_SELF']; ?>?module=matpel&act=edit">
                        
						<table class='putih' border="0" width="650">
						<tr>
						<td colspan="4">
						<ul class="templatemo_list">
						<li><strong>DATA MATA PELAJARAN</strong></li>
						</ul>
						</td>
						</tr>
						<tr>
						<td>Kd Mata Pelajaran</td> <td colspan="3"> <input type="text" readonly name="kd_matpel" size="10" value="<?php echo $r[kd_matpel]; ?>" /> </td>                        
						</tr>
						<tr>
						<td>Mata Pelajaran </td> <td colspan="3"> <input type="text" name="nama_matpel" size="30" value="<?php echo $r[nama_matpel]; ?>"/> </td>                        
						</tr>					
						
						<tr>
						<td>						
						</td>
						<td colspan="3">				
                        <input type="submit" value="Simpan" id="submit" name="submit" class="submit_btn float_l" />
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="reset" value="Reset" id="reset" name="reset" class="submit_btn float_l" />
						</td>						
						</tr>
						</table>
                    </form>
					<?php
					break;
					
				
				}
				?>				
        		</div>
                </div>
                
            	<div class="cleaner"></div>   
            </div>        
        </div>
    
    </div> <!-- end of templatemo_wrapper -->
</div> <!-- end of templatemo_outer_wrapper -->

<?php
	include "../footer.php";
?>

</body>
</html>
